package models
{
	import flash.media.Camera;
	import flash.media.Microphone;
	import flash.net.SharedObject;
	
	import org.dexter.sendDexterEvent;

	public class LocalSetting
	{
		public var so:SharedObject = SharedObject.getLocal("localSetting");
		public function set bufferTime(v:Number):void{
			setValue("bufferTime",v);
		}
		public function get bufferTime():Number{
			return so.data["bufferTime"] == null?0.1:so.data["bufferTime"];
		}
		public function set userName(v:String):void{
			setValue("userName",v);
		}
		public function get userName():String{
			return so.data["userName"];
		}
		public function get camera():int{
			return so.data["camera"];
		}
		public function set camera(v:int):void{
			setValue("camera",v);
		}
		public function get cameraSetting():Object{
			return so.data["cameraSetting"];
		}
		public function set cameraSetting(v:Object):void{
			setValue("cameraSetting",v);
			if(cam){
				cam.setMode(v.width,v.height,v.fps);
				cam.setQuality(v.bandwidth,v.quality);
				cam.setKeyFrameInterval(v.keyFarmeInterval);
			}
		}
		public function get microphone():int{
			return so.data["microphone"];
		}
		public function set microphone(v:int):void{
			setValue("microphone",v);
		}
		protected function setValue(name:String,value:Object):void{
			so.data[name] = value;
			try{
				so.flush();
			}catch(e:Error){
				sendDexterEvent("localSettingError",name,value);
			}
		}
		public function get cam():Camera{
			if(camera < Camera.names.length){
				return Camera.getCamera(camera.toString());
			}else{
				return Camera.getCamera();
			}
		}
		public function get mic():Microphone{
			if(microphone< Microphone.names.length){
				return Microphone.getMicrophone(microphone);
			}else{
				return Microphone.getMicrophone();
			}
		}
	}
}